package com.matchmealpha;

import java.io.IOException;
import java.net.MalformedURLException;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.FacebookError;
import com.facebook.android.Facebook.DialogListener;

public class MatchMeFacebookActivity extends Activity {

	Facebook facebook = new Facebook(MatchMeTabWidget.FACEBOOK_APP_ID);
	private boolean login;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		Bundle bund = this.getIntent().getExtras();
		login = bund.getBoolean("login");
		if (login) {
			facebook.authorize(this, new DialogListener() {
				@Override
				public void onComplete(Bundle values) {
					finish();
				}

				@Override
				public void onFacebookError(FacebookError error) {
					finish();
				}

				@Override
				public void onError(DialogError e) {
					finish();
				}

				@Override
				public void onCancel() {
					finish();
				}
			});
		}
		else {
			try {
				facebook.logout(this);
				//finish();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}

	@Override
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		facebook.authorizeCallback(requestCode, resultCode, data);
	}
}